home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / cameraMakeNode.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  6.0 KB  |  202 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  7 May 1997
  22. //  Author:         cdt
  23. //
  24. //  Procedure Name:
  25. //      cameraMakeNode
  26. //
  27. //  Description:
  28. //      Creates extra camera nodes for the center of interest and up vector.
  29. //
  30. //  Input Arguments:
  31. //      count - Number of nodes to create.
  32. //      camera - The camera transform name. Pass "" to use selection.
  33. //
  34. //  Return Value:
  35. //      None.
  36. //
  37.  
  38. //
  39. //  Procedure Name:
  40. //      createLocator
  41. //
  42. proc string createLocator(string $name, float $position[])
  43. {
  44.     string $targets[] = `spaceLocator -name $name -position 0 0 0`;
  45.     string $target = $targets[0];
  46.  
  47.     // Set locator to have screen space icon
  48.     string $targetShapes[] = `listRelatives $target`;
  49.     string $targetShape = $targetShapes[0];
  50.     setAttr ($targetShape+".visibility") false;
  51.     setAttr ($target+".displayRotatePivot") true;
  52.  
  53.     move -absolute $position[0] $position[1] $position[2];
  54.  
  55.     return $target;
  56. }
  57.  
  58. //
  59. //  Procedure Name:
  60. //      doLookAt
  61. //
  62. proc string doLookAt( string $camera )
  63. {
  64.     string $shapes[] = `listRelatives -shapes $camera`;
  65.  
  66.     // Begin computing the center of interest in world space
  67.     //
  68.  
  69.     float $coi[] = `camera -q -worldCenterOfInterest $camera`;
  70.  
  71.     //
  72.     // End computing the center of interest in world space
  73.  
  74.     string $target = createLocator($camera+"_aim", $coi);
  75.  
  76.     string $lookAt = `createNode -name ($camera+"_group") "lookAt"`;
  77.  
  78.     // Fix for BUG 118280, the two node camera used to use "Scene Up"; but
  79.     // this is problematic because if the camera is loaded into a scene with
  80.     // a different up axis, the camera will have a different orientation than
  81.     // the one it had been created for it.
  82.     //
  83.  
  84.     // Orient the camera depending on users current up axis preferences.
  85.     setAttr ".worldUpType" 3;
  86.     if (`upAxis -q -axis` == "z") {
  87.         setAttr ".worldUpVector" -type double3 0 0 1;
  88.     }
  89.     else {
  90.         setAttr ".worldUpVector" -type double3 0 1 0;
  91.     }
  92.  
  93.     setAttr ".aimVector" -type double3 0 0 -1;
  94.  
  95.     connectAttr ($target+".tx") ($lookAt+".target[0].targetTranslateX");
  96.     connectAttr ($target+".ty") ($lookAt+".target[0].targetTranslateY");
  97.     connectAttr ($target+".tz") ($lookAt+".target[0].targetTranslateZ");
  98.     connectAttr ($target+".rp") ($lookAt+".target[0].targetRotatePivot");
  99.     connectAttr ($target+".rpt") ($lookAt+".target[0].targetRotateTranslate");
  100.     connectAttr ($target+".pm") ($lookAt+".target[0].targetParentMatrix");
  101.  
  102.     connectAttr ($camera+".pim") ($lookAt+".constraintParentInverseMatrix");
  103.     connectAttr ($camera+".t") ($lookAt+".constraintTranslate");
  104.     connectAttr ($camera+".rp") ($lookAt+".constraintRotatePivot");
  105.     connectAttr ($camera+".rpt") ($lookAt+".constraintRotateTranslate");
  106.  
  107.     connectAttr ($lookAt+".constraintRotateX") ($camera+".rotateX");
  108.     connectAttr ($lookAt+".constraintRotateY") ($camera+".rotateY");
  109.     connectAttr ($lookAt+".constraintRotateZ") ($camera+".rotateZ");
  110.     connectAttr ($lookAt+".distanceBetween") ($shapes[0]+".centerOfInterest");
  111.  
  112.     // Parent
  113.     parent $camera $lookAt;
  114.     parent $target $lookAt;
  115.  
  116.     return $lookAt;
  117. }
  118.  
  119. //
  120. //  Procedure Name:
  121. //      doSelect
  122. //
  123. proc doSelect( string $camera )
  124. {
  125.     string $view = getCameraNode( "view", $camera );
  126.     string $up = getCameraNode( "up", $camera );
  127.  
  128.     string $selects = $camera;
  129.     if ($up != "") $selects += " " + $up;
  130.     if ($view != "") $selects += " " + $view;
  131.  
  132.     eval ("select "+$selects);
  133. }
  134.  
  135. //
  136. //  Procedure Name:
  137. //      cameraMakeNode
  138. //
  139. global proc cameraMakeNode (int $count, string $camera)
  140. {
  141.     if ($camera == "") {
  142.         string $selected[] = `ls -selection`;
  143.         $camera = $selected[0];
  144.     }
  145.  
  146.     string $lookAt = getCameraNode( "lookAt", $camera );
  147.     string $view = getCameraNode( "view", $camera );
  148.     string $up = getCameraNode( "up", $camera );
  149.  
  150.     switch ($count) {
  151.     case 1:
  152.         if ($lookAt != "") ungroup $lookAt;
  153.         if ($view != "") delete $view;
  154.         if ($up != "") delete $up;
  155.  
  156.         break;
  157.  
  158.     case 2:
  159.         // Does a look at already exist?
  160.         if ($lookAt != "") {
  161.             // Is there already an up?
  162.             if ($up != "") delete $up;
  163.         }
  164.         else {
  165.             doLookAt $camera;
  166.         }
  167.  
  168.         break;
  169.  
  170.     case 3:
  171.         // Does a look at not already exist?
  172.         if ($lookAt == "") {
  173.             $lookAt = doLookAt($camera);
  174.         }
  175.  
  176.         // Begin computing the up in world space
  177.         //
  178.  
  179.         float $upOrigin[] = `camera -q -worldUp $camera`;
  180.         float $eye[] = `camera -q -position $camera`;
  181.  
  182.         $upOrigin[0] = $upOrigin[0] * 2.0 + $eye[0];
  183.         $upOrigin[1] = $upOrigin[1] * 2.0 + $eye[1];
  184.         $upOrigin[2] = $upOrigin[2] * 2.0 + $eye[2];
  185.  
  186.         //
  187.         // End computing the up in world space
  188.  
  189.         string $up = createLocator($camera+"_up", $upOrigin);
  190.         connectAttr ($up+".wm") ($lookAt+".worldUpMatrix");
  191.  
  192.         // Put the up node under the look at
  193.         parent $up $lookAt;
  194.  
  195.         setAttr ($lookAt+".worldUpType") 1; // Use object
  196.  
  197.         break;
  198.     }
  199.  
  200.     doSelect( $camera );
  201. }
  202.